package org.gangcai.mac.shop.activity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import com.blankj.utilcode.util.SPUtils;

import org.gangcai.mac.shop.R;
import org.gangcai.mac.shop.bean.CommonResonseBean;
import org.gangcai.mac.shop.common.MultiStatusActivity;
import org.gangcai.mac.shop.constants.Constant;
import org.gangcai.mac.shop.manager.RetrofitManager;
import org.gangcai.mac.shop.oberver.CommonObserver;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;

public class AddNewICCardActivity extends MultiStatusActivity {

    @BindView(R.id.cardName)
    EditText cardName;
    @BindView(R.id.cardBank)
    EditText cardBank;
    @BindView(R.id.cardNum)
    EditText cardNum;
    @BindView(R.id.nextStep)
    Button nextStep;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTitleBarView(titlebar, "添加银行卡");
        ButterKnife.bind(this);
    }

    @Override
    public int getContentView() {
        return R.layout.activity_add_new_iccard;
    }

    @OnClick(R.id.nextStep)
    public void onViewClicked() {
        prompDialog.showLoading("请等待");
        RetrofitManager.create().add_bankcard(SPUtils.getInstance().getString("uid"), cardName.getText().toString(), cardBank.getText().toString(), cardNum.getText().toString())
                .compose(this.<CommonResonseBean>bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CommonObserver<CommonResonseBean>(prompDialog) {
                    @Override
                    public void onSuccess(CommonResonseBean value) {
                        if (value.getCode() == Constant.CODE_SUCC) {
                            prompDialog.showSuccess("添加成功");
                            finish();
                        }
                    }
                });

    }

}
